/*
 * HomeService.java
 *
 * Created on 02 March 2006, 16:44
 *
 * To change this template, choose Tools | Options and locate the template under
 * the Source Creation and Management node. Right-click the template and choose
 * Open. You can then make changes to the template in the Source Editor.
 */
package web.services;

//import business.pojos.User;
import se392.ateam2006.user.UserEntity;
import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
import se392.ateam2006.authentication.GroupEntity;
import se392.ateam2006.resourcemgmt.room.RoomEntity;
import web.util.BusinessFacadeDelegate;

/**
 *
 * @author Phil
 */
public class HomeService extends GenericService {

    /** Creates a new instance of HomeService */
    public HomeService() {
    }

    public String executePreDispatch(HttpServletRequest request,
            ServletContext context)
            throws Exception {
        BusinessFacadeDelegate delegate = this.getDelegate(request.getSession());
        boolean createUsers = false;
        if (createUsers) {
            UserEntity[] users = new UserEntity[5];
            users[0] = new UserEntity("administrator@borth.ac.uk", "Administrator", "Admin");
            users[1] = new UserEntity("ccf4@aber.ac.uk", "Caroline", "Fletcher");
            users[2] = new UserEntity("sac4@aber.ac.uk", "Sam", "Carter");
            users[3] = new UserEntity("rrc4@aber.ac.uk", "Rob", "Clark");
            users[4] = new UserEntity("mcs3@aber.ac.uk", "Mike", "Skaife");

            GroupEntity admin = new GroupEntity("admin");
            delegate.addGroup(admin);
            for (int i = 0; i < users.length; i++) {
                users[i].setPassword("admin");
                delegate.createUser(users[i]);
                delegate.addUserToGroup(users[i], admin);
            }
            
        }
        
        RoomEntity roomOne = new RoomEntity("caz", 5, "sun lounge", "test");
        RoomEntity roomTwo = new RoomEntity("sam", 5, "sun lounge", "mike");
        
        delegate.addRoom(roomTwo);
        delegate.addRoom(roomOne);
        
        delegate.setLoggedInUser(delegate.getUser("sac4@aber.ac.uk"));        
        return "display";
    }

    public void executePostDispatch(HttpServletRequest request,
            ServletContext context)
            throws Exception {

    }
}
